package com.bsfcs.rag.entity;

import com.bsfcs.rag.enums.JobCategory;
import jakarta.persistence.*;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
@Entity
@Table(name = "xxhpromworkhours")
public class WorkHour {
    private String formatDate(Date date) {
        if (date == null) return null;
        // 根据需要选择合适的日期格式
        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return formatter.format(date);
    }

    public WorkHour() {}

    public WorkHour(String id, String parentId, String registrant, String job_category, String describe,
                    Date job_date, BigDecimal job_duration, Date start_time, Date end_time, Date create_time,
                    String output, String registrant_deptname) {
        this.id = id;
        this.parentId = parentId;
        this.registrant = registrant;
        this.job_category = JobCategory.fromCode(job_category).getDisplayName();
        this.describe = describe;
        this.job_date_str = formatDate(job_date);
        this.job_duration = job_duration;
        this.start_time_str = formatDate(start_time);
        this.end_time_str = formatDate(end_time);
        this.create_time_str = formatDate(create_time);
        this.output = output;
        this.registrant_deptname = registrant_deptname;
    }

    @Id
    @Column(name = "id")
    private String id;
    
    @Column(name = "parentid")
    private String parentId; // 关联到任务表的id字段

    /**
     * 登记人
     */
    @Column(name = "registrant")
    private String registrant;

    @Column(name = "job_category")
    private String job_category;

    @Column(name = "describe")
    private String describe;

    @Column(name = "job_date")
    private Date job_date;

    private String job_date_str;

    @Column(name = "job_duration")
    private BigDecimal job_duration;

    @Column(name = "start_time")
    private Date start_time;

    private String start_time_str;

    @Column(name = "end_time")
    private Date end_time;

    private String end_time_str;

    @Column(name = "create_time")
    private Date create_time;

    private String create_time_str;

    @Column(name = "output")
    private String output;
    
    @Column(name = "registrant_deptname")
    private String registrant_deptname;
}